﻿using System;
using System.Windows.Data;
using BizControl.Library.BusinessObjects.Marks;
using System.Windows.Media;
using System.Windows.Shapes;
using BizControl.Library.BusinessObjects.Activities;

namespace BizControl.Presentation.ActivityEditModule.Converters
{
  public class ConditionTypeToElementNameConverter : IMultiValueConverter
  {
    private readonly int TypeIndex = 0;
    private readonly int ElementIndex = 1;

    #region IMultiValueConverter Members

    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
      if (values[TypeIndex] != null && values[ElementIndex] != null)
      {
        var type = (ConditionType)Enum.Parse(typeof(ConditionType), values[TypeIndex].ToString());
        if (type == ConditionType.ActivityRequired)
        {
          if ((values[ElementIndex] as ActivityInfo) != null)
            return (values[ElementIndex] as ActivityInfo).ShortenDescription;
        }
        if (type == ConditionType.MarkRequired || type == ConditionType.SkillRequired)
        {
          if ((values[ElementIndex] as MarkInfo) != null)
            return (values[ElementIndex] as MarkInfo).Name;
        }
      }
      return string.Empty;
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
    {
      return null;
    }

    #endregion
  }
}
